<?php
class Ext_ModelsMapper
{
    public function setDbTable($dbTable)
    {
        if (is_string($dbTable)) {
            $dbTable = new $dbTable();
        }
        if (!$dbTable instanceof Zend_Db_Table_Abstract) {
            throw new Exception('Invalid table data gateway provided');
        }
        $this->_dbTable = $dbTable;
  
        return $this;
    }

    public function getDbTable()
    {
        return $this->_dbTable;
    }
    public function find($id, $model )
    {
        $result = $this->getDbTable()->find( $id );
        if (0 == count( $result )) {
            return;
        }
        $row = $result->current();
       	$entry = new $this->_model();
        $entry->_setProperties( $row, $this );
    }
    public function fetchAll( $where = null )
    {
        $resultSet = $this->getDbTable()->fetchAll( $where );
        //var_dump($resultSet);die();
        $entries   = array();
        
        foreach ($resultSet as $row) {
            $entry = new $this->_model;
            $entry->_setProperties( $row, $this );
            $entries[] = $entry;
        }
        return $entries;
    }
    
}